<!--  -->
<template>
  <div class=''>
    <basic-container v-loading="loading">
      <el-row>
        <el-col :span="24">
          <div style="margin-left:30px;">
            日期：
            <el-date-picker
              @change="MonthChange"
              v-model="value"
              type="month"
              format="yyyy-MM"
              value-format="yyyy-MM"
              placeholder="选择月"
              :clearable="false"
            >
            </el-date-picker>
          </div>
        </el-col>
      </el-row>
      <el-row
        :gutter="20"
        style="display:flex;justify-content: center;align-items: center;"
      >
        <el-col
          :span="11"
          class="borderbox"
        >
          <div class="title">
            <span>市场管理服务费</span>
            <span
              class="more"
              @click="goService"
            >更多>></span>
          </div>
          <el-row>
            <el-col :span="12">
              <div class="item">
                <span>本月应收(元)：</span>
                <span>{{managementList.sum}}</span>
              </div>
              <div class="item">
                <span>已缴纳(元)：</span>
                <span>{{managementList.payment}}</span>
              </div>
              <div class="item">
                <span>待缴纳(元)：</span>
                <span>{{managementList.noPayment}}</span>
              </div>
            </el-col>
            <el-col :span="12">
              <div
                class="yuan"
                style="padding-top:10px;"
              >
                <div style="padding-right:40px;">待缴率</div>
                <el-progress
                  type="dashboard"
                  :percentage="managementList.noPaymentRate"
                  :color="color"
                  :width='85'
                ></el-progress>
              </div>
              <div class="yuan">
                <div style="padding-right:40px;">逾期率</div>
                <el-progress
                  type="dashboard"
                  :percentage="managementList.overdueRate"
                  :color="colors"
                  :width='85'
                ></el-progress>
              </div>
            </el-col>
          </el-row>
          <div style="width:100%;height:300px;">
            <div id="management"></div>
          </div>
        </el-col>
        <el-col
          :span="11"
          class="borderbox"
        >
          <div class="title">
            <span>租金</span>
            <span
              class="more"
              @click="goMoreRent"
            >更多>></span>
          </div>
          <el-row>
            <el-col :span="12">
              <div class="item">
                <span>本月应收(元)：</span>
                <span>{{RentList.sum}}</span>
              </div>
              <div class="item">
                <span>已缴纳(元)：</span>
                <span>{{RentList.payment}}</span>
              </div>
              <div class="item">
                <span>待缴纳(元)：</span>
                <span>{{RentList.noPayment}}</span>
              </div>
            </el-col>
            <el-col :span="12">
              <div
                class="yuan"
                style="padding-top:10px;"
              >
                <div style="padding-right:40px;">待缴率</div>
                <el-progress
                  type="dashboard"
                  :percentage="RentList.noPaymentRate"
                  :color="color"
                  :width='85'
                ></el-progress>
              </div>
              <div class="yuan">
                <div style="padding-right:40px;">逾期率</div>
                <el-progress
                  type="dashboard"
                  :percentage="RentList.overdueRate"
                  :color="colors"
                  :width='85'
                ></el-progress>
              </div>
            </el-col>
          </el-row>
          <div style="width:100%;height:300px;">
            <div id="rent"></div>
          </div>
        </el-col>
      </el-row>
      <el-row
        :gutter="20"
        style="display:flex;justify-content: center;align-items: center;"
      >
        <el-col
          :span="11"
          class="borderbox"
        >
          <div class="title">
            <span>水费</span>
            <span
              class="more"
              @click="goMoreWater"
            >更多>></span>
          </div>
          <el-row>
            <el-col :span="12">
              <div class="item">
                <span>本月应收(元)：</span>
                <span>{{WaterList.sumWater}}</span>
              </div>
              <div class="item">
                <span>已缴纳(元)：</span>
                <span>{{WaterList.paymentWater}}</span>
              </div>
              <div class="item">
                <span>待缴纳(元)：</span>
                <span>{{WaterList.noPaymentWater}}</span>
              </div>
            </el-col>
            <el-col :span="12">
              <div
                class="yuan"
                style="padding-top:10px;"
              >
                <div style="padding-right:40px;">待缴率</div>
                <el-progress
                  type="dashboard"
                  :percentage="WaterList.noPaymentRateWater"
                  :color="color"
                  :width='85'
                ></el-progress>
              </div>
              <div class="yuan">
                <div style="padding-right:40px;">逾期率</div>
                <el-progress
                  type="dashboard"
                  :percentage="WaterList.overdueRateWater"
                  :color="colors"
                  :width='85'
                ></el-progress>
              </div>
            </el-col>
          </el-row>
          <div style="width:100%;height:300px;">
            <div id="water"></div>
          </div>
        </el-col>
        <el-col
          :span="11"
          class="borderbox"
        >
          <div class="title">
            <span>电费</span>
            <span
              class="more"
              @click="goMoreElec"
            >更多>></span>
          </div>
          <el-row>
            <el-col :span="12">
              <div class="item">
                <span>本月应收(元)：</span>
                <span>{{electricityList.sumElectric}}</span>
              </div>
              <div class="item">
                <span>已缴纳(元)：</span>
                <span>{{electricityList.paymentElectric}}</span>
              </div>
              <div class="item">
                <span>待缴纳(元)：</span>
                <span>{{electricityList.noPaymentElectric}}</span>
              </div>
            </el-col>
            <el-col :span="12">
              <div
                class="yuan"
                style="padding-top:10px;"
              >
                <div style="padding-right:40px;">待缴率</div>
                <el-progress
                  type="dashboard"
                  :percentage="electricityList.noPaymentRateElectric"
                  :color="color"
                  :width='85'
                ></el-progress>
              </div>
              <div class="yuan">
                <div style="padding-right:40px;">逾期率</div>
                <el-progress
                  type="dashboard"
                  :percentage="electricityList.overdueRateElectric"
                  :color="colors"
                  :width='85'
                ></el-progress>
              </div>
            </el-col>
          </el-row>
          <div style="width:100%;height:300px;">
            <div id="electricity"></div>
          </div>
        </el-col>
      </el-row>
    </basic-container>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { Chart } from '@antv/g2';
import { management, utilities } from '@/api/datareport/index'
export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data () {
    // 这里存放数据
    return {
      loading: false,
      value: '',
      percentage: 10,
      color: '#1989fa',
      colors: '#f56c6c',
      managementList: {
        sum: '',
        payment: '',
        noPayment: '',
        lineChart: [],
        overdueRate: 0,
        noPaymentRate: 0
      },
      managementChartList: [],
      RentList: {
        sum: '',
        payment: '',
        noPayment: '',
        lineChart: [],
        overdueRate: 0,
        noPaymentRate: 0
      },
      RentChartList: [],
      WaterList: {
        sum: '',
        payment: '',
        noPayment: '',
        lineChart: [],
        overdueRate: 0,
        noPaymentRate: 0
      },
      WaterChartList: [],
      electricityList: {
        sum: '',
        payment: '',
        noPayment: '',
        lineChart: [],
        overdueRate: 0,
        noPaymentRate: 0
      },
      electricityChartList: []
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    goService () {
      // this.$router.push({ path: '/market/datareport/propertyaccount', query: {} })
      let routeData = this.$router.resolve({ path: '/market/datareport/propertyaccount', query: {} });
      window.open(routeData.href, '_blank');
    },
    goMoreRent () {
      // this.$router.push({ path: '/market/datareport/StandingBook', query: {} })
      let routeData = this.$router.resolve({ path: '/market/rent/index', query: {} });
      window.open(routeData.href, '_blank');
    },
    goMoreWater () {
      let routeData = this.$router.resolve({ path: '/market/mrcost/index', query: {} });
      window.open(routeData.href, '_blank');
    },
    goMoreElec () {
      let routeData = this.$router.resolve({ path: '/market/mrcost/index', query: {} });
      window.open(routeData.href, '_blank');
    },
    MonthChange () {
      this.getList()
    },
    getList () {
      this.loading = true
      document.getElementById("management").innerHTML = ""
      document.getElementById("rent").innerHTML = ""
      document.getElementById("water").innerHTML = ""
      document.getElementById("electricity").innerHTML = ""
      this.getManagement(0)
      this.getManagement(1)
      this.getUtilities()
    },
    getManagement (type) {
      management({ time: this.value, type: type }).then(res => {
        if (type == 0) {
          this.managementList = res.data.data
          this.managementList.lineChart.forEach(item => {
            let time = item.month
            item.month = item.month + '月'
            setTimeout(() => { this.managementChartList.push(item) }, time)
          })
          const management = new Chart({
            container: 'management', // 指定图表容器 ID
            height: 300, // 指定图表高度
            autoFit: true,
            padding: [25, 25, 25, 50]
          });
          setTimeout(() => {
            this.renderChart(management, this.managementChartList)
          }, 12)
        } else {
          this.RentList = res.data.data
          this.RentList.lineChart.forEach(item => {
            let time = item.month
            item.month = item.month + '月'
            setTimeout(() => { this.RentChartList.push(item) }, time)
          })
          const rent = new Chart({
            container: 'rent', // 指定图表容器 ID
            height: 300, // 指定图表高度
            autoFit: true,
            padding: [25, 25, 25, 50]
          });
          setTimeout(() => {
            this.renderChart(rent, this.RentChartList)
          }, 12)
        }
      })
    },
    getUtilities () {
      utilities({ time: this.value }).then(res => {
        this.electricityList = res.data.data.electr
        this.WaterList = res.data.data.water
        this.WaterList.lineChartWater.forEach(item => {
          let time = item.month
          item.month = item.month + '月'
          setTimeout(() => { this.WaterChartList.push(item) }, time)
        })
        this.electricityList.lineChartElectric.forEach(item => {
          let time = item.month
          item.month = item.month + '月'
          setTimeout(() => { this.electricityChartList.push(item) }, time)
        })
        const water = new Chart({
          container: 'water', // 指定图表容器 ID
          height: 300, // 指定图表高度
          autoFit: true,
          padding: [25, 25, 25, 50]
        });
        const electricity = new Chart({
          container: 'electricity', // 指定图表容器 ID
          height: 300, // 指定图表高度
          autoFit: true,
          padding: [25, 25, 25, 50]
        });
        setTimeout(() => {
          this.renderChart(water, this.WaterChartList)
          this.renderChart(electricity, this.electricityChartList)
        }, 12)
        this.loading = false
      })
    },
    renderChart (value, data) {
      value.data(data);
      value.scale({
        month: {
          range: [0.05, 0.95],
        },
        value: {
          alias: '已缴纳(元)',
          min: 0,
          nice: true
        },
      });
      value.tooltip({
        showCrosshairs: true, // 展示 Tooltip 辅助线
        shared: true,
      });
      value.line().position('month*value').label('value');
      value.point().position('month*value');
      value.render();
    },
    getCurrTime () {
      let date = new Date()
      let y = date.getFullYear()
      let m = '0' + (date.getMonth() + 1)
      return y + '-' + m.substring(m.length - 2)
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created () {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {
    this.value = this.getCurrTime()
    this.getList()
  },
  beforeCreate () { }, // 生命周期 - 创建之前
  beforeMount () { }, // 生命周期 - 挂载之前
  beforeUpdate () { }, // 生命周期 - 更新之前
  updated () { }, // 生命周期 - 更新之后
  beforeDestroy () { }, // 生命周期 - 销毁之前
  destroyed () { }, // 生命周期 - 销毁完成
  activated () { } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.borderbox {
  padding: 20px 30px 20px 30px !important;
  margin: 10px;
  position: relative;
  box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.1);
  .title {
    display: flex;
    justify-content: space-between;
    height: 40px;
    align-items: center;
    .more {
      cursor: pointer;
      color: blue;
    }
  }
  .item {
    height: 60px;
    display: flex;
    align-items: center;
  }
  .yuan {
    display: flex;
    align-items: center;
  }
  .title::before {
    position: absolute;
    content: "";
    width: 9px;
    background-color: blue;
    left: 10px;
    height: 30px;
    border-radius: 2px;
  }
}
</style>